//
//  LZCreatePromoitonHeaderView.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCreatePromoitonHeaderView.h"
#import "Masonry.h"

@implementation LZCreatePromoitonHeaderView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = UIColorFromRGB(0xffffff, 1);

        [self configView];
        [self addAutoLayout];
    }
    return self;
}

- (void)configView {
    [self addSubview:self.selectButton];
    [self addSubview:self.titleLabel];
    [self addSubview:self.indicatorImage];
    [self addSubview:self.line];
}

- (void)addAutoLayout {
    WS(weakSelf);
    
    [self.selectButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.leading.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.leading.mas_equalTo(weakSelf.selectButton.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(weakSelf.indicatorImage.mas_leading);
    }];
    
    [self.indicatorImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.trailing.mas_equalTo(weakSelf.mas_trailing).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(12, 6));
    }];
    
    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.mas_equalTo(0.6);
    }];
}

- (void)selectButton:(UIButton *)sender {

    if (self.selectButtonActionBlock) {
        self.selectButtonActionBlock(sender);
    }
}

- (UIButton *)selectButton {

    if (_selectButton == nil) {
        _selectButton = [[UIButton alloc] init];
        [_selectButton setImage:[UIImage imageNamed:@"lz_select_no"] forState:UIControlStateNormal];
        [_selectButton addTarget:self action:@selector(selectButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _selectButton;
}

- (UILabel *)titleLabel {

    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        if ([LZLanguageManager shareInstance].getLanguageType == LanguageType_Ar) {
            _titleLabel.textAlignment = NSTextAlignmentRight;
        } else {
            _titleLabel.textAlignment = NSTextAlignmentLeft;
        }
    }
    
    return _titleLabel;
}

- (UIImageView *)indicatorImage {

    if (_indicatorImage == nil) {
        _indicatorImage = [[UIImageView alloc] init];
        _indicatorImage.image = [UIImage imageNamed:@"lz_show"];
    }
    
    return _indicatorImage;
}

- (UIView *)line {

    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
    }
    
    return _line;
}

@end
